﻿public class MyStack<T>
{
    private T[] StackArray { get; set; }
    private int Top { get; set; }
    private int Capacity { get; set; }

    public MyStack(int capacity)
    {
        if (capacity <= 0)
            throw new ArgumentOutOfRangeException(nameof(capacity));

        Capacity = capacity;
        InitStack();
    }

    public void InitStack()
    {
        StackArray = new T[Capacity];
        Top = -1;
    }

    public void ClearStack()
    {
        Top = -1;
    }

    public void Push(T item)
    {
        if (IsFull())
            throw new InvalidOperationException();

        Top++;
        StackArray[Top] = item;
    }

    public T Pop()
    {
        if (IsEmpty())
            throw new InvalidOperationException();

        T topItem = StackArray[Top];
        Top--;
        return topItem;
    }

    public bool IsEmpty()
    {
        return Top == -1;
    }

    public bool IsFull()
    {
        return Top == Capacity - 1;
    }

    public int GetCount()
    {
        return Top + 1;
    }
}